{% extends 'base.html' %}
{% load static %}
{% load humanize %}
{% load comment_form_tags %}

{% block title %}
    <title>{{ blog.title }}_详情页</title>
{% endblock %}

{% block css %}
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.css">
    <link rel="stylesheet" type="text/css" href="{% static  'css/typo.css' %}">
    <link rel="stylesheet" type='text/css' href="{% static 'css/animate.css' %}">
    <link rel="stylesheet" type='text/css' href="{% static 'lib/prism/prism.css' %}">
    <link rel="stylesheet" type='text/css' href="{% static 'lib/tocbot/tocbot.css' %}">
    <link rel="stylesheet" type='text/css' href="{% static '/css/me.css' %}">
{% endblock %}

{% block content %}
    <!--中间内容-->
    <div id="waypoint" class="m-container-small m-padded-tb-big animated fadeIn">
        <div class="ui container">
            <div class="ui top attached segment">
                <div class="ui horizontal link list">
                    <div class="item">
                        <img src="https://avatars.githubusercontent.com/u/23349356" alt="" class="ui avatar image">
                        <div class="content"><a href="#" class="header">{{ blog.author.get_full_name }}</a></div>
                    </div>
                    <div class="item">
                        <i class="calendar icon"></i> {{ blog.created|naturaltime }}
                    </div>
                    <div class="item">
                        <i class="eye icon"></i> {{ blog.total_views }}
                    </div>
                </div>
            </div>
            <div class="ui attached segment">
                <!--图片区域-->
                <img src="{{ blog.image.url }}" alt="" class="ui fluid rounded image">
            </div>
            <div class="ui attached padded segment">
                <!--内容-->
                <div class="ui right aligned basic segment">
                    <a href="{% url 'blog:type_detail' blog.category.id %}">
                        <div class="ui orange basic label">{{ blog.category }}</div>
                    </a>
                </div>

                <h2 class="ui center aligned header">{{ blog.title }}</h2>
                <br>

                <div id="content" class="typo typo-selection js-toc-content m-padded-lr-responsive m-padded-tb-large">
                    {{ blog.body|safe }}
                </div>

                <!--标签-->
                <div class="m-padded-lr-responsive">
                    <a href="{% url 'blog:tag_detail' blog.tag.id %}">
                        <div class="ui basic teal left pointing label">{{ blog.tag }}</div>
                    </a>
                </div>

                <!--赞赏-->
                <div class="ui center aligned basic segment">
                    <button id="payButton" class="ui orange basic circular button">赞赏</button>
                </div>
                <div class="ui payQR flowing popup transition hidden">
                    <div class="ui orange basic label">
                        <div class="ui images" style="font-size: inherit !important;">
                            <div class="image">
                                <img src="{% static 'images/zfb.png' %}" alt="" class="ui rounded bordered image"
                                     style="width: 120px">
                                <div>支付宝</div>
                            </div>
                            <div class="image">
                                <img src="{% static 'images/wechat.png' %}" alt="" class="ui rounded bordered image"
                                     style="width: 120px">
                                <div>微信</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="ui attached positive message">
                <!--博客信息-->
                <div class="ui middle aligned grid">
                    <div class="eleven wide column">
                        <ui class="list">
                            <li>作者：{{ blog.author.get_full_name }}</li>
                            <li>发表时间：{{ blog.created }}</li>
                            <li>版权声明：自由转载-非商用-非衍生-保持署名（创意共享3.0许可证）</li>
                            <li>公众号转载：请在文末添加作者公众号二维码</li>
                        </ui>
                    </div>
                    <div class="five wide column">
                        <img src="{% static 'images/wechat.png' %}" alt=""
                             class="ui right floated rounded bordered image"
                             style="width: 110px">
                    </div>
                </div>
            </div>
            {#                        {% show_comment_form blog %}#}
            <div id="comment-container" class="ui bottom attached segment">
                <!--留言区域列表-->
                <div class="ui teal segment">
                    <div class="ui threaded comments">
                        <h3 class="ui dividing header">Comments</h3>
                          <div class="comment">
                            {% for comment in comments %}
                                <a class="avatar">
                                    <img src="https://avatars.githubusercontent.com/u/23349356">
                                </a>
                                <div class="content">
                                    <a class="author">{{ comment.nickname }}</a>
                                    <div class="metadata">
                                        <span class="date">发布于{{ comment.created_time|naturaltime }}</span>
                                    </div>
                                    <div class="text">
                                        {{ comment.content }}
                                    </div>
{#                                    <div class="actions">#}
{#                                        <a class="reply">回复</a>#}
{#                                    </div>#}
                                </div>
                            {% endfor %}
                        <!-- 一级评论 -->
{#                        <div class="comment">#}
{#                            <a class="avatar">#}
{#                                <img src="https://unsplash.it/100/100?image=1005">#}
{#                            </a>#}
{#                            <div class="content">#}
{#                                <a class="author">Elliot Fu</a>#}
{#                                <div class="metadata">#}
{#                                    <span class="date">Yesterday at 12:30AM</span>#}
{#                                </div>#}
{#                                <div class="text">#}
{#                                    <p>This has been very useful for my research. Thanks as well!</p>#}
{#                                </div>#}
{#                                <div class="actions">#}
{#                                    <a class="reply">回复</a>#}
{#                                </div>#}
{#                            </div>#}
{#                            <!-- 二级回复评论 -->#}
{#                            <div class="comments">#}
{#                                <div class="comment">#}
{#                                    <a class="avatar">#}
{#                                        <img src="https://unsplash.it/100/100?image=1005">#}
{#                                    </a>#}
{#                                    <div class="content">#}
{#                                        <a class="author">Jenny Hess</a>#}
{#                                        <div class="metadata">#}
{#                                            <span class="date">Just now</span>#}
{#                                        </div>#}
{#                                        <div class="text">#}
{#                                            Elliot you are always so right :)#}
{#                                        </div>#}
{#                                        <div class="actions">#}
{#                                            <a class="reply">回复</a>#}
{#                                        </div>#}
{#                                    </div>#}
{#                                </div>#}
{#                            </div>#}
{#                        </div>#}
                    </div>
                </div>

                <form action="{% url 'comments:comment' blog.id %}" method="POST">
                    {% csrf_token %}
                    <div class="ui form">
                        <div class="field">
                            <textarea name="content" placeholder="请输入评论信息..."></textarea>
                        </div>

                        <div class="fields">
                            <div class="field m-mobile-wide m-margin-bottom-small">
                                <div class="ui left icon input">
                                    <i class="user icon"></i>
                                    <input type="text" name="nickname" placeholder="姓名">
                                </div>

                            </div>

                            <div class="field m-mobile-wide m-margin-bottom-small">
                                <div class="ui left icon input">
                                    <i class="mail icon"></i>
                                    <input type="text" name="email" placeholder="邮箱">
                                </div>
                            </div>

                            <div class="field  m-margin-bottom-small m-mobile-wide">
                                <button class="ui teal button m-mobile-wide" type="submit"><i class="edit icon"></i>发布
                                </button>
                            </div>
                        </div>
                        <div>
                            {% if comment_form.errors %}
                                {% for field in comment_form %}
                                    {% for error in field.errors %}
                                        <strong>{{ error }}</strong>
                                        <br>
                                    {% endfor %}
                                {% endfor %}
                            {% else %}
                                {{ msg }}
                            {% endif %}
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <div id="toolbar" class="m-padded m-fixed m-right-bottom" style="display: none">
        <div class="ui vertical icon buttons ">
            <button type="button" class="ui toc teal button">目录</button>
            <a href="#comment-container" class="ui teal button">留言</a>
            <button class="ui wechat icon button"><i class="weixin icon"></i></button>
            <div id="toTop-button" class="ui icon button"><i class="chevron up icon"></i></div>
        </div>
    </div>

    <div class="ui toc-container flowing popup transition hidden" style="width: 250px!important;">
        <ol class="js-toc"></ol>
    </div>

    <div id="qrcode" class="ui wechat-qr flowing popup transition hidden " style="width: 130px !important;">
        <!--<img src="./static/images/wechat.jpg" alt="" class="ui rounded image" style="width: 120px !important;">-->
    </div>
    <br>
    <br>
{% endblock %}

{% block javascript %}
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/jquery.scrollto@2.1.2/jquery.scrollTo.min.js"></script>
    <script src="{% static 'lib/prism/prism.js' %}"></script>
    <script src="{% static 'lib/tocbot/tocbot.min.js' %}"></script>
    <script src="{% static 'lib/qrcode/qrcode.min.js' %}"></script>
    <script src="{% static 'lib/waypoints/jquery.waypoints.min.js' %}"></script>
    <script>
        $('.menu.toggle').click(function () {
            $('.m-item').toggleClass('m-mobile-hide');
        });

        $('#payButton').popup({
            popup: $('.payQR.popup'),
            on: 'click',
            position: 'bottom center'
        });

        tocbot.init({
            // Where to render the table of contents.
            tocSelector: '.js-toc', // 生成的目录放在哪儿 , 这里用css选中
            // Where to grab the headings to build the table of contents.
            contentSelector: '.js-toc-content', // 生成目录的源在那儿 , 就是给谁生成目录
            // Which headings to grab inside of the contentSelector element. // 能给生成的几级标题
            headingSelector: 'h1, h2, h3 , h4 , h5 , h6',
            hasInnerContainers: true,
        });

        $('.toc.button').popup({
            popup: $('.toc-container.popup'),
            on: 'click',
            position: 'left center'
        });

        $('.wechat').popup({
            popup: $('.wechat-qr'),
            position: 'left center'
        });

        var qrcode = new QRCode("qrcode", {
            text: "http://jindo.dev.naver.com/collie",
            width: 110,
            height: 110,
            colorDark: "#000000",
            colorLight: "#ffffff",
            correctLevel: QRCode.CorrectLevel.H
        });

        $('#toTop-button').click(function () {
            $(window).scrollTo(0, 500);
        });


        var waypoint = new Waypoint({
            element: document.getElementById('waypoint'),
            handler: function (direction) {
                if (direction == 'down') {
                    $('#toolbar').show(100);
                } else {
                    $('#toolbar').hide(500);
                }
                console.log('Scrolled to waypoint!  ' + direction);
            }
        })
    </script>
{% endblock %}




